<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>utils — Utilities Module &mdash; Documentation</title>
    <link rel="stylesheet" href="_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="Documentation" href="index.html" />
    <link rel="up" title="3. Server Side API" href="server_side_api.html" />
    <link rel="next" title="email_lib — Email" href="email_lib.html" />
    <link rel="prev" title="doc — Document (ORM)" href="doc.html" /> 
  </head>
  <body>
    <div style="background-color: #FFF; text-align: left; padding: 8px 0px"><img src="_static/banner300910.gif"></div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="email_lib.html" title="email_lib — Email"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="doc.html" title="doc — Document (ORM)"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Documentation</a> &raquo;</li>
          <li><a href="server_side_api.html" accesskey="U">3. Server Side API</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">utils</span></tt> &#8212; Utilities Module</a><ul>
<li><a class="reference external" href="#date-and-time-functions">Date and Time Functions</a></li>
<li><a class="reference external" href="#datatype-conversions">Datatype Conversions</a></li>
<li><a class="reference external" href="#defaults">Defaults</a></li>
<li><a class="reference external" href="#file-blob-functions">File (BLOB) Functions</a></li>
<li><a class="reference external" href="#email-functions">Email Functions</a></li>
<li><a class="reference external" href="#other-functions">Other Functions</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="doc.html"
                                  title="previous chapter"><tt class="docutils literal docutils literal docutils literal"><span class="pre">doc</span></tt> &#8212; Document (ORM)</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="email_lib.html"
                                  title="next chapter"><tt class="docutils literal docutils literal docutils literal"><span class="pre">email_lib</span></tt> &#8212; Email</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="_sources/utils_server.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-utils">
<h1><tt class="xref docutils literal"><span class="pre">utils</span></tt> &#8212; Utilities Module<a class="headerlink" href="#module-utils" title="Permalink to this headline">¶</a></h1>
<div class="section" id="date-and-time-functions">
<h2>Date and Time Functions<a class="headerlink" href="#date-and-time-functions" title="Permalink to this headline">¶</a></h2>
<dl class="data">
<dt id="utils.user_format">
<tt class="descclassname">utils.</tt><tt class="descname">user_format</tt><a class="headerlink" href="#utils.user_format" title="Permalink to this definition">¶</a></dt>
<dd><p>User format specified in <a class="reference external" href="glossary.html#term-control-panel"><em class="xref">Control Panel</em></a></p>
<p>Examples:</p>
<ul class="simple">
<li>dd-mm-yyyy</li>
<li>mm-dd-yyyy</li>
<li>dd/mm/yyyy</li>
</ul>
</dd></dl>

<dl class="function">
<dt id="utils.getdate">
<tt class="descclassname">utils.</tt><tt class="descname">getdate</tt><big>(</big><em>string_date</em><big>)</big><a class="headerlink" href="#utils.getdate" title="Permalink to this definition">¶</a></dt>
<dd>Coverts string date (yyyy-mm-dd) to datetime.date object</dd></dl>

<dl class="function">
<dt id="utils.add_days">
<tt class="descclassname">utils.</tt><tt class="descname">add_days</tt><big>(</big><em>string_date</em>, <em>days</em><big>)</big><a class="headerlink" href="#utils.add_days" title="Permalink to this definition">¶</a></dt>
<dd>Adds <cite>days</cite> to the given <cite>string_date</cite></dd></dl>

<dl class="function">
<dt id="utils.now">
<tt class="descclassname">utils.</tt><tt class="descname">now</tt><big>(</big><big>)</big><a class="headerlink" href="#utils.now" title="Permalink to this definition">¶</a></dt>
<dd>Returns <cite>time.strftime(&#8216;%Y-%m-%d %H:%M:%S&#8217;)</cite></dd></dl>

<dl class="function">
<dt id="utils.nowdate">
<tt class="descclassname">utils.</tt><tt class="descname">nowdate</tt><big>(</big><big>)</big><a class="headerlink" href="#utils.nowdate" title="Permalink to this definition">¶</a></dt>
<dd>Returns time.strftime(&#8216;%Y-%m-%d&#8217;)</dd></dl>

<dl class="function">
<dt id="utils.get_first_day">
<tt class="descclassname">utils.</tt><tt class="descname">get_first_day</tt><big>(</big><em>date</em>, <em>d_years=0</em>, <em>d_months=0</em><big>)</big><a class="headerlink" href="#utils.get_first_day" title="Permalink to this definition">¶</a></dt>
<dd>Returns the first day of the month for the date specified by date object
Also adds <cite>d_years</cite> and <cite>d_months</cite> if specified</dd></dl>

<dl class="function">
<dt id="utils.get_last_day">
<tt class="descclassname">utils.</tt><tt class="descname">get_last_day</tt><big>(</big><em>dt</em><big>)</big><a class="headerlink" href="#utils.get_last_day" title="Permalink to this definition">¶</a></dt>
<dd>Returns last day of the month using:
<cite>get_first_day(dt, 0, 1) + datetime.timedelta(-1)</cite></dd></dl>

<dl class="function">
<dt id="utils.formatdate">
<tt class="descclassname">utils.</tt><tt class="descname">formatdate</tt><big>(</big><em>dt</em><big>)</big><a class="headerlink" href="#utils.formatdate" title="Permalink to this definition">¶</a></dt>
<dd>Convers the given string date to <a title="utils.user_format" class="reference internal" href="#utils.user_format"><tt class="xref docutils literal"><span class="pre">user_format</span></tt></a></dd></dl>

</div>
<div class="section" id="datatype-conversions">
<h2>Datatype Conversions<a class="headerlink" href="#datatype-conversions" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="utils.dict_to_str">
<tt class="descclassname">utils.</tt><tt class="descname">dict_to_str</tt><big>(</big><em>args</em>, <em>sep='&amp;'</em><big>)</big><a class="headerlink" href="#utils.dict_to_str" title="Permalink to this definition">¶</a></dt>
<dd>Converts a dictionary to URL</dd></dl>

<dl class="function">
<dt id="utils.isNull">
<tt class="descclassname">utils.</tt><tt class="descname">isNull</tt><big>(</big><em>v</em><big>)</big><a class="headerlink" href="#utils.isNull" title="Permalink to this definition">¶</a></dt>
<dd>Returns true if v=&#8217;&#8217; or v is <cite>None</cite></dd></dl>

<dl class="function">
<dt id="utils.has_common">
<tt class="descclassname">utils.</tt><tt class="descname">has_common</tt><big>(</big><em>l1</em>, <em>l2</em><big>)</big><a class="headerlink" href="#utils.has_common" title="Permalink to this definition">¶</a></dt>
<dd>Returns true if there are common elements in lists l1 and l2</dd></dl>

<dl class="function">
<dt id="utils.flt">
<tt class="descclassname">utils.</tt><tt class="descname">flt</tt><big>(</big><em>s</em><big>)</big><a class="headerlink" href="#utils.flt" title="Permalink to this definition">¶</a></dt>
<dd>Convert to float (ignore commas)</dd></dl>

<dl class="function">
<dt id="utils.cint">
<tt class="descclassname">utils.</tt><tt class="descname">cint</tt><big>(</big><em>s</em><big>)</big><a class="headerlink" href="#utils.cint" title="Permalink to this definition">¶</a></dt>
<dd>Convert to integer</dd></dl>

<dl class="function">
<dt id="utils.cstr">
<tt class="descclassname">utils.</tt><tt class="descname">cstr</tt><big>(</big><em>s</em><big>)</big><a class="headerlink" href="#utils.cstr" title="Permalink to this definition">¶</a></dt>
<dd>Convert to string</dd></dl>

<dl class="function">
<dt id="utils.str_esc_quote">
<tt class="descclassname">utils.</tt><tt class="descname">str_esc_quote</tt><big>(</big><em>s</em><big>)</big><a class="headerlink" href="#utils.str_esc_quote" title="Permalink to this definition">¶</a></dt>
<dd>Escape quotes</dd></dl>

<dl class="function">
<dt id="utils.replace_newlines">
<tt class="descclassname">utils.</tt><tt class="descname">replace_newlines</tt><big>(</big><em>s</em><big>)</big><a class="headerlink" href="#utils.replace_newlines" title="Permalink to this definition">¶</a></dt>
<dd>Replace newlines by &#8216;&lt;br&gt;&#8217;</dd></dl>

<dl class="function">
<dt id="utils.parse_val">
<tt class="descclassname">utils.</tt><tt class="descname">parse_val</tt><big>(</big><em>v</em><big>)</big><a class="headerlink" href="#utils.parse_val" title="Permalink to this definition">¶</a></dt>
<dd>Converts to simple datatypes from SQL query results</dd></dl>

<dl class="function">
<dt id="utils.fmt_money">
<tt class="descclassname">utils.</tt><tt class="descname">fmt_money</tt><big>(</big><em>amount</em>, <em>fmt = '%.2f'</em><big>)</big><a class="headerlink" href="#utils.fmt_money" title="Permalink to this definition">¶</a></dt>
<dd>Convert to string with commas for thousands, millions etc</dd></dl>

</div>
<div class="section" id="defaults">
<h2>Defaults<a class="headerlink" href="#defaults" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="utils.get_defaults">
<tt class="descclassname">utils.</tt><tt class="descname">get_defaults</tt><big>(</big><big>)</big><a class="headerlink" href="#utils.get_defaults" title="Permalink to this definition">¶</a></dt>
<dd>Get dictionary of default values from the <a class="reference external" href="glossary.html#term-control-panel"><em class="xref">Control Panel</em></a></dd></dl>

<dl class="function">
<dt id="utils.set_default">
<tt class="descclassname">utils.</tt><tt class="descname">set_default</tt><big>(</big><em>key</em>, <em>val</em><big>)</big><a class="headerlink" href="#utils.set_default" title="Permalink to this definition">¶</a></dt>
<dd>Set / add a default value to <a class="reference external" href="glossary.html#term-control-panel"><em class="xref">Control Panel</em></a></dd></dl>

</div>
<div class="section" id="file-blob-functions">
<h2>File (BLOB) Functions<a class="headerlink" href="#file-blob-functions" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="utils.get_file">
<tt class="descclassname">utils.</tt><tt class="descname">get_file</tt><big>(</big><em>fname</em><big>)</big><a class="headerlink" href="#utils.get_file" title="Permalink to this definition">¶</a></dt>
<dd>Returns result set of ((fieldname, blobcontent, lastmodified),) for a file of name or id <cite>fname</cite></dd></dl>

</div>
<div class="section" id="email-functions">
<h2>Email Functions<a class="headerlink" href="#email-functions" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="utils.validate_email_add">
<tt class="descclassname">utils.</tt><tt class="descname">validate_email_add</tt><big>(</big><em>email_str</em><big>)</big><a class="headerlink" href="#utils.validate_email_add" title="Permalink to this definition">¶</a></dt>
<dd>Validates the email string</dd></dl>

<dl class="function">
<dt id="utils.sendmail">
<tt class="descclassname">utils.</tt><tt class="descname">sendmail</tt><big>(</big><em>recipients</em>, <em>sender=''</em>, <em>msg=''</em>, <em>subject='</em><span class="optional">[</span>, <em>No Subject</em><span class="optional">]</span>, <em>'</em>, <em>parts=</em><span class="optional">[</span><span class="optional">]</span>, <em>cc=</em><span class="optional">[</span><span class="optional">]</span>, <em>attach=</em><span class="optional">[</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#utils.sendmail" title="Permalink to this definition">¶</a></dt>
<dd>Send an email. For more details see <a title="email_lib.sendmail" class="reference external" href="email_lib.html#email_lib.sendmail"><tt class="xref docutils literal"><span class="pre">email_lib.sendmail()</span></tt></a></dd></dl>

</div>
<div class="section" id="other-functions">
<h2>Other Functions<a class="headerlink" href="#other-functions" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="utils.getCSVelement">
<tt class="descclassname">utils.</tt><tt class="descname">getCSVelement</tt><big>(</big><em>v</em><big>)</big><a class="headerlink" href="#utils.getCSVelement" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the CSV value of <cite>v</cite>, For example:</p>
<ul class="simple">
<li>apple becomes &#8220;apple&#8221;</li>
<li>hi&#8221;there becomes &#8220;hi&#8221;&#8220;there&#8221;</li>
</ul>
</dd></dl>

<dl class="function">
<dt id="utils.generate_hash">
<tt class="descclassname">utils.</tt><tt class="descname">generate_hash</tt><big>(</big><big>)</big><a class="headerlink" href="#utils.generate_hash" title="Permalink to this definition">¶</a></dt>
<dd>Generates reandom hash for session id</dd></dl>

<dl class="function">
<dt id="utils.getTraceback">
<tt class="descclassname">utils.</tt><tt class="descname">getTraceback</tt><big>(</big><big>)</big><a class="headerlink" href="#utils.getTraceback" title="Permalink to this definition">¶</a></dt>
<dd>Returns the traceback of the Exception</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="email_lib.html" title="email_lib — Email"
             >next</a> |</li>
        <li class="right" >
          <a href="doc.html" title="doc — Document (ORM)"
             >previous</a> |</li>
        <li><a href="index.html">Documentation</a> &raquo;</li>
          <li><a href="server_side_api.html" >3. Server Side API</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2010, Rushabh Mehta.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>